package com.mediacloud.app.newsmodule.view

import android.view.View
import androidx.viewpager2.widget.ViewPager2
import kotlin.math.abs

/**
 * @author zengtao Created on 2022/6/15
 * viewpager2 PageTransformer (画廊)
 */
class GalleryTransformer : ViewPager2.PageTransformer {
    companion object {
        private const val TARGET_ALPHA = 0.5f
        private const val TARGET_SCALE = 0.8f
    }
    override fun transformPage(page: View, position: Float) {
        if (position < -1 || position > 1) {
            //当前页面左侧以及右侧的页面效果
          //  page.alpha = TARGET_ALPHA
            page.scaleX = TARGET_SCALE
            page.scaleY = TARGET_SCALE
        } else {
            //从不可见变为可见效果

            //透明度效果
//            if (position <= 0) {
//                page.alpha =
//                    TARGET_ALPHA + TARGET_ALPHA * (1 + position)
//            } else {
//                page.alpha =
//                    TARGET_ALPHA + TARGET_ALPHA * (1 - position)
//            }
            //缩放效果
            val scale = TARGET_SCALE.coerceAtLeast(1 - abs(position))
            page.scaleX = scale
            page.scaleY = scale
        }
    }

}